package com.hualan.sfzy.service.mind.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.mind.MindKnowledge;
import com.hualan.sfzy.mapper.mind.MindKnowledgeMapper;
import com.hualan.sfzy.service.BaseServiceImp;
import com.hualan.sfzy.service.mind.MindKnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MindKnowledgeServiceImpl extends BaseServiceImp<MindKnowledge> implements MindKnowledgeService {
    @Autowired
    private MindKnowledgeMapper mindKnowledgeMapper;

    // 重写新增方法，自动设置创建时间
    @Override
    public int add(MindKnowledge mindKnowledge) {
        // 自动填充当前时间到 createTime 字段
        mindKnowledge.setCreateTime(new Date());
        // 调用 mapper 插入数据（del 字段已在 XML 中默认设为 0）
        return mindKnowledgeMapper.insert(mindKnowledge);
    }

    @Override
    public Map<String, Object> findByPage(Integer pageNum, Integer pageSize, MindKnowledge mindKnowledge) {
        PageHelper.startPage(pageNum, pageSize);
        List<MindKnowledge> list = mindKnowledgeMapper.select(mindKnowledge);
        PageInfo<MindKnowledge> pageInfo = new PageInfo<>(list);

        Map<String, Object> map = new HashMap<>();
        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        map.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return map;
    }
}